<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/back/include/incTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
<script type="text/javascript">
<!--
$(document).ready(function() {
	/*
	$.ajaxSetup({
		  contextType: 'application/json'
	});
	$.post('/admin/code/list.json'
			, function(data, status){
				_setTree(data);
	}, 'json');
	*/
	_setTreeAdd(5,88,'sample');
	_setTreeAdd(8,89,'test');
});
function _setTree(data){
	
}
function _setTreeAdd(parent,codeNo,codeText){
	var parentNode = $('#treeList').children().find('span[id='+parent+']').parent();
	parentNode.css('background-color', 'red');
	//alert(parentNode.parent('li').has('ul').length); // 0
	//<li><span id="codeNo">codeText</span></li>
	var newNode = '<li><span id="'+codeNo+'">'+codeText+'</span></li>';
	if(parentNode.has('ul').length > 0){
	//	parentNode.first('ul').html(newNode);
		$(newNode).appendTo(parentNode.find('>ul'));
	}else{
	//	parentNode.add('<ul>'+newNode+'</ul>');
		$('<ul>'+newNode+'</ul>').appendTo(parentNode);
	}
}
function _setTreeRemove(data){
	
}
//-->
</script>
</head>
<body>
<div id="treeList">
<c:set var="upLevel" value="1" />
<c:forEach items="${codeList}" var="item" varStatus="c">
	<c:if test="${c.first}"><c:out value="<ul>" escapeXml="false" /></c:if>
	<c:if test="${upLevel > item.level}" >
		<c:forEach begin="1" end="${ upLevel - item.level }" step="1">
			<c:out value="</ul></li>" escapeXml="false" />
		</c:forEach>
	</c:if>
	<li><span id="${item.codeNo}">${item.value}(${item.codeNo})</span>
	<c:if test="${item.isLeaf  eq 0}"><c:out value="<ul>" escapeXml="false" /></c:if>
	<c:if test="${item.isLeaf  eq 1}"><c:out value="</li>" escapeXml="false" /></c:if>
	<c:if test="${c.last}">
		<c:if test="${1 < item.level}" >
			<c:forEach begin="1" end="${item.level - 1}" step="1">
				<c:out value="</ul></li>" escapeXml="false" />
			</c:forEach>
		</c:if>
	<c:out value="</ul>" escapeXml="false" />
	</c:if>
	<c:set var="upLevel" value="${item.level}" />
</c:forEach>
</div>
</body>
</html>